<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>转发内容</title>
    <script type="text/javascript" src="/js/jquery.js"></script>
    <script src="http://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
</head>
<body>
分享页面测试

<script>

    var title = "";
    var desc = "";
    var urllink = window.location.href;
    var imgUrl="";

    $(function(){
        var data = {id:5};
        var url = "/task/getTaskInfo";
        $.ajax({
            type: "POST",
            async: false,
            dataType: 'json',
            contentType: "application/json; charset=utf-8",
            data: JSON.stringify(data),
            url: url,
            success: function(res){
                console.log(res);
                if(res.code == 200){
                    var datas = res.data;
                    title= datas.title;
                    desc = datas.title;
                    imgUrl = datas.pic;
                }else{
                    alert(res.msg);
                }
            },
            error: function(){

            },
            complete: function(){
            }
        });
    });
    wx.config({
        debug: false,
        appId: "${appId}",
        timestamp: "${timestamp}",
        nonceStr: "${nonceStr}",
        signature: "${signature}",
        jsApiList: [
        //所有要调用的 API 都要加到这个列表中
            "onMenuShareAppMessage",
            "onMenuShareTimeline"
        ]
    });

    wx.ready(function () {   //需在用户可能点击分享按钮前就先调用
        wx.onMenuShareAppMessage({
            title: title, // 分享标题
            desc: desc, // 分享描述
            link: urllink, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: imgUrl, // 分享图标
            type: 'link', // 分享类型,music、video或link，不填默认为link
            success: function (res) {
                alert('分享成功');
            },
            cancel: function (res) {
                alert('分享失败');
                // 用户取消分享后执行的回调函数
            },
        });

        wx.onMenuShareTimeline({
            title: title, // 分享标题
            link: urllink, // 分享链接，该链接域名或路径必须与当前页面对应的公众号JS安全域名一致
            imgUrl: imgUrl, // 分享图标
            success: function (res) {
                alert('分享成功');
            },
            cancel: function (res) {
                alert('分享失败');
                // 用户取消分享后执行的回调函数
            },
        });


    });

</script>
</body>

</html>
